﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using System.Text;
using System.Threading.Tasks;
using ServeNHL.Helpers;


namespace ServeNHL.Models
{
    public class UserRoleModel
    {
        public USER_ROLE User_Role { get; set; }
        public ORGANIZATION Organization { get; set; }
        public USER User { get; set; }


        /// <summary>
        /// Adds a UserRole and organization to the database
        /// </summary>
        /// <param name="userRoleID">Role object associated with the permissions of a user</param>
        /// <param name="organization">Organization object to save to the database</param>
        /// <returns>roleID</returns>
        public int UserOrganizationAdd(USER_ROLE userRoleID, ORGANIZATION organization)
        {
            int roleID = 0;

            using (var dbconn = new fclick_dbEntities())
            {
                dbconn.USER_ROLE.Add(userRoleID);
                dbconn.SaveChanges();


                var curOrganization = new ORGANIZATION
                {
                    ORG_ID = organization.ORG_ID,
                    STATUS = organization.STATUS,
                    CREATED_DATE = Helpers.createDate.getCreateDate(),
                    LAST_MOD_DATE = organization.LAST_MOD_DATE,

                };

                dbconn.ORGANIZATIONs.Add(curOrganization);
                dbconn.SaveChanges();

                roleID = curOrganization.ORG_ID;
            }
            return roleID;
        } // End of public int UserOrganizationAdd(USER_ROLE userRoleID, ORGANIZATION organization)
    }
}